#include <M5EPD.h>
#include <NTPClient.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <time.h>

#define _TASK_STATUS_REQUEST  // Compile with support for StatusRequest
                              // functionality - triggering tasks on status
                              // change events in addition to time only
#include <TaskScheduler.h>

#include "app_main_controller.h"

// 协作式任务调度器
static Scheduler gTaskScheduler;

// 应用代码控制器
static AppMainController gAppController;

void updateSensorStatus() {
  gAppController.UpdateSensorState();
  gAppController.ShowMainView();
}

void setup() {
  gAppController.Initialize();

  // static Task gSensorTask;
  // gSensorTask.set(5000, TASK_FOREVER, updateSensorStatus);
  // gTaskScheduler.addTask(gSensorTask);
  // gSensorTask.enable();
  static Task sensorTask(5000, TASK_FOREVER, updateSensorStatus,
                         &gTaskScheduler, true);
}

void loop() {
  // 协作式调度器，任务调度
  gTaskScheduler.execute();
}
